(require easy)

(def (pitch-integer? v)
     (and (exact-integer? v)
          (<= -99 v 99)))

(def (pitch-interval? v)
     (and (exact-integer? v)
          (<= -198 v 198)))

(def (pitchclass-integer? v)
     (and (exact-integer? v)
          (<= 0 v 11)))

(def (pitchclass-interval? v)
     (and (exact-integer? v)
          (<= -11 v 11)))

(definterface pitchtype
  (defclass (pitch [pitch-integer? integer]))
  (defclass (pitchclass [pitchclass-integer? integer])))


(def chord? (list-of pitch-integer?))
(def pitch-intervals? (list-of pitch-interval?))

(def pitchclass-chord? (list-of pitchclass-integer?))
(def pitchclass-intervals? (list-of pitchclass-interval?))


;;(def twelve-tone-row? (list-of/length pitchclass-integer? 12))

(def twelve-tone-row?
     (both (list-of/length pitchclass-integer? 12)
           (=>* (cmp-sort real-cmp)
                (.group =)
                (.filter (=>* .length (> 1)))
                null?)))

(TEST
 > (twelve-tone-row? '(1))
 #f
 > (twelve-tone-row? '(1 2 3 4 5 6 7 8 9 10 11 12))
 #f
 > (twelve-tone-row? '(1 2 3 4 5 6 7 8 9 10 11 0))
 #t
 > (twelve-tone-row? '(1 2 3 4 5 6 7 8 9 10 10 0))
 #f)

